package com.example.smartcity.ui.Adapter;

import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.smartcity.R;
import com.example.smartcity.ui.Bean.CommandBean;

import java.util.ArrayList;


public class CommandListAdapter extends RecyclerView.Adapter<CommandListAdapter.MyViewHodler> {

    private int resource;
    private ArrayList<CommandBean> list;

    public CommandListAdapter(int resource, ArrayList<CommandBean> list) {
        this.resource = resource;
        this.list = list;
    }


    @NonNull
    @Override
    public MyViewHodler onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(resource,parent,false);
        return new CommandListAdapter.MyViewHodler(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHodler holder, int position) {
        holder.TV_Message.setText(list.get(position).getMessage());
        holder.TV_time.setText(list.get(position).getTime());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyViewHodler extends RecyclerView.ViewHolder{
        TextView TV_Message;
        TextView TV_time;
        public MyViewHodler(@NonNull View itemView) {
            super(itemView);
            TV_Message = itemView.findViewById(R.id.TV_Content);
            TV_time = itemView.findViewById(R.id.TV_time);
        }
    }
}
